package dao.impl;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import util.DBController;

import model.Rates;
import model.Rates;
import dao.intf.RatesDao;

public class RatesDaoImpl implements RatesDao {

	public List<Rates> getRatesList() {
		List<Rates> ratesList = new ArrayList<Rates>();
		
		ResultSet rs = DBController.retrieve("Rates", null, null);
		
		try {
			if( rs != null ) {
				while( rs.next() ) {
					Rates rates = new Rates();
					rates.setId(rs.getString("ID"));
					rates.setDescription(rs.getString("Description"));
					try{rates.setMax(rs.getInt("maxNight"));
					}catch(Exception ex){}
					rates.setMin(rs.getInt("minNight"));
					rates.setDiscountPercent(rs.getInt("DiscountPercent"));
					rates.setTypeId(rs.getString("TypeID"));
					
					ratesList.add(rates);
				}
			}
			DBController.disconnect();
		} catch (Exception e) {
			System.out.println("Error at method getRatesList() of RatesDaoImpl.");
			e.printStackTrace();
		}
		
		return ratesList;
	}

	public Rates getRatesById(String id) {
		Rates rates = new Rates();
		
		ResultSet rs = DBController.retrieve("Rates", null, "ID='"+id+"'");
		
		try {
			if( rs != null ) {
				while( rs.next() ) {
					rates.setId(rs.getString("ID"));
					rates.setDescription(rs.getString("Description"));
					try{rates.setMax(rs.getInt("max"));
					}catch(Exception ex){}
					rates.setMin(rs.getInt("min"));
					rates.setDiscountPercent(rs.getInt("DiscountPercent"));
					rates.setTypeId(rs.getString("TypeID"));
				}
			}
			DBController.disconnect();
		} catch (Exception e) {
			System.out.println("Error at method getRatesById() of RatesDaoImpl.");
			e.printStackTrace();
		}
		
		return rates;
	}

	
}
